import re
res = set()
with open('1.log') as f:
    for i in f:
        # print(i)
        r = re.findall('next and w(\d+), w(\d+)', i)
        if len(r) != 0:
            res.add(f'w{r[0][0]}, w{r[0][1]}')
print(res)